<?php
require_once('../../../includes/classes/core.php');
$action	= $_REQUEST['act'];
$error	= '';
$data	= '';
$id  	= $_REQUEST['id'];

switch ($action) {
    case 'get_list':
	    $count = $_REQUEST['count'];
	    $hidden = $_REQUEST['hidden'];
	    $tab = $_REQUEST['tab'];
	    	$rResult = mysql_query("	    	    
	    	    SELECT 		`a_letter`.`id`,
                					CONCAT( '№: ბ-',`a_letter`.`id`) as latter,
                					`a_letter`.fact_end_date AS date,
                					sum(IF(warehouse_detail.type=2 AND b_letter_details.part_type_id=2,0,b_letter_details.price)) AS price,
                					client_objects.`name` AS client,
                					a_letter.`comment`
                FROM 			`a_letter`
                
                JOIN	client_objects ON client_objects.id = a_letter.client_object_id
                JOIN	warehouse ON a_letter.id = warehouse.a_letter_id
                JOIN	warehouse_detail ON warehouse.id = warehouse_detail.warehouse_id AND warehouse_detail.actived=1
                JOIN 	b_letter_details ON b_letter_details.a_letter_id=a_letter.id AND warehouse_detail.id =b_letter_details.warehouse_detail_id
                WHERE 		a_letter.actived =1 AND a_letter.invoice_id=$id
                GROUP BY 	a_letter.id
                		UNION
                SELECT 		`d_letter`.`id`,
                					CONCAT( '№: ე-',`d_letter`.`id`),
                					`d_letter`.fact_end_date,
                					SUM( IF(warehouse_detail.type = 2, 0, e_letter_details.price)),
                					client_objects.`name`,
                					d_letter.`comment`
                FROM 		`d_letter`
                JOIN 		client_objects ON client_objects.id = d_letter.client_object_id
                JOIN 		warehouse ON d_letter.id = warehouse.d_letter_id
                JOIN 		warehouse_detail ON warehouse.id = warehouse_detail.warehouse_id AND warehouse_detail.actived=1
                JOIN 		e_letter_details ON e_letter_details.d_letter_id=d_letter.id AND warehouse_detail.id =e_letter_details.warehouse_detail_id
                WHERE 		d_letter.actived =1 AND d_letter.invoice_id=$id
                GROUP BY 	d_letter.id
	    			");	   

		$data = array( "aaData"	=> array());

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$data['aaData'][] = $aRow;
		}


        break;
     case 'get_edit_page':
        	$letter_id	= $_REQUEST['id'];
        	$tab 		= $_REQUEST['tab'];
        	$inv 		= $_REQUEST['inv'];
        	if ($inv=='inv' & $tab==1){
        	$page		= GetPage('',$tab);
        	$data 		= array('page'	=> $page);
        	}
        	else{
        	$page		= GetPage( GetAletterInfo($letter_id) );
        	$data 		= array('page'	=> $page);
}

        break;
    default:
       $error = 'Action is Null';}

$data['error'] = $error;
echo json_encode($data);
function addNull($sum){
	if($sum != '' && $sum != '0'){
		$parts = explode('.', $sum);
		$sum1 ='';
		$sum1.= $parts[0];
		if( $parts[1] == ''){
			$sum1.= '.00';
		}else{
			$sum1 = $sum;
		}
		return $sum1;
	}else{
		return '0.00';
	}
}
function print1($aletter_id){
	$rsql = mysql_query("
	    SELECT    b_letter_details.barcode,
                    				production.`name`,	
                    				COUNT(DISTINCT part1.barcode) AS toneti,
                    				COUNT(DISTINCT part2.id) AS barabani,
                    				COUNT(DISTINCT part3.id) AS magnituri,
                    				COUNT(DISTINCT part4.id) as rezini,
                    				COUNT(DISTINCT part5.id) as gamwmendi,
                    				COUNT(DISTINCT part6.id) as dozirebis,
                    				COUNT(DISTINCT part7.id) AS chipi,
                    				COUNT(DISTINCT part8.id) AS korpusi,
                    				COUNT(DISTINCT part9.id) AS not_service,
                    				max(warehouse_detail.type),                    				
	                                sum(IF(warehouse_detail.type=2 AND b_letter_details.part_type_id=2,0.00,b_letter_details.price))
                    FROM `b_letter_details`
                    JOIN  a_letter on b_letter_details.a_letter_id=a_letter.id
                    LEFT JOIN  production ON SUBSTR(b_letter_details.barcode, 6, 4) = production.id
                    LEFT JOIN  client ON SUBSTR(b_letter_details.barcode, 2, 4) = client.id
                    JOIN  warehouse_detail ON b_letter_details.warehouse_detail_id=warehouse_detail.id AND warehouse_detail.actived=1
                    LEFT JOIN  b_letter_details part1 ON  part1.part_type_id=2  AND part1.id =b_letter_details.id
                    LEFT JOIN  b_letter_details part2 ON  part2.part_type_id=3  AND part2.id =b_letter_details.id
                    LEFT JOIN  b_letter_details part3 ON  part3.part_type_id=4  AND part3.id =b_letter_details.id
                    LEFT JOIN  b_letter_details part4 ON  part4.part_type_id=5  AND part4.id =b_letter_details.id
                    LEFT JOIN  b_letter_details part5 ON  part5.part_type_id=6  AND part5.id =b_letter_details.id
                    LEFT JOIN  b_letter_details part6 ON  part6.part_type_id=7  AND part6.id =b_letter_details.id
                    LEFT JOIN  b_letter_details part7 ON  part7.part_type_id=8  AND part7.id =b_letter_details.id
                    LEFT JOIN  b_letter_details part8 ON  part8.part_type_id=9  AND part8.id =b_letter_details.id
                    LEFT JOIN  b_letter_details part9 ON  part9.part_type_id=16 AND part9.id =b_letter_details.id
                    WHERE      b_letter_details.a_letter_id=$aletter_id
                    GROUP BY b_letter_details.barcode
	    
	    
	    
	    ");
			GLOBAL $sum;
			while ( $aRow = mysql_fetch_array( $rsql ) ){
			$data .= '<tr style="background-color: #D9D9D9;border:1px solid black !important;">';
					for ( $i = 0 ; $i < 13 ; $i++ ){
					if($i< 2 || $i > 10){
					if( $i == 11){
					if( $aRow[$i] == 2 ){
					$aRow[12] = '0.00';
							$data .= '<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;"><img src="media/images/0.gif"></td>';
					}else{
					$data .= '<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">&nbsp;</td>';
					}
					}else{
					$data .='<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
					}

					}else{
					if($aRow[$i] == 1){
					$data .= '<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;"><img src="media/images/0.gif"></td>';
					}else{
					$data .= '<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">&nbsp;</td>';
					}
					}
					if($i == 12){
					$sum = floatval($sum) + floatval($aRow[$i]);
					}
					}
					$data .= '</tr>';
			}
			return $data;
}
function print2($dletter_id){
	$rsql = mysql_query("SELECT			printer_parts_type.`name`,
			production.`name`,
			warehouse_detail.barcode,
			IF(warehouse_detail.type = 2, 0, printer_pricelist.price)
			FROM    	warehouse_producing
			LEFT JOIN	warehouse_detail ON warehouse_detail.id	= warehouse_producing.warehouse_detail_id
			LEFT JOIN	warehouse ON warehouse.id = warehouse_detail.warehouse_id
			LEFT JOIN	d_letter ON d_letter.id   = warehouse.d_letter_id
			LEFT JOIN	production ON production.id = warehouse_detail.prod_id
			LEFT JOIN	printer_parts_type ON printer_parts_type.id = warehouse_producing.printer_part_id
			LEFT JOIN	client_objects ON client_objects.id = d_letter.client_object_id
			LEFT JOIN	client ON client.id = client_objects.client_id
			INNER JOIN  printer_pricelist ON client.id = printer_pricelist.client_id AND warehouse_producing.printer_part_id = printer_pricelist.parts_type AND warehouse_detail.prod_id  = printer_pricelist.production_id
			WHERE		d_letter.id = '$dletter_id'");
	GLOBAL $sum;
	$data = '';
	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr>';
		for ( $i = 0 ; $i < 4 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
			if( $i == 3){
				$sum = floatval($sum) + floatval($aRow[$i]);
			}
		}
		$data .= '</tr>';
	}
	return $data;
}
function print3($aletter_id){
	$rsql = mysql_query("SELECT production.`name`,
                                			COUNT(*)
                                FROM warehouse_detail
                                LEFT JOIN	`production` ON `production`.`id` = warehouse_detail.prod_id
                                LEFT JOIN  warehouse ON warehouse.id=warehouse_id
                                WHERE warehouse.a_letter_id= '$aletter_id'
                                			AND `warehouse_detail`.`type` = 1
                                			AND `warehouse_detail`.`actived` = 1
                                GROUP BY warehouse_detail.prod_id");
	GLOBAL $sum;
	$data = '';
	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr>';
		for ( $i = 0 ; $i < 2 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
		}
		$data .= '</tr>';
	}
	return $data;
}
function print4($dletter_id){
	$rsql = mysql_query("SELECT production.`name`,
                                			COUNT(*)
                                FROM warehouse_detail
                                LEFT JOIN	`production` ON `production`.`id` = warehouse_detail.prod_id
                                LEFT JOIN  warehouse ON warehouse.id=warehouse_id
                                WHERE warehouse.d_letter_id= '$dletter_id'
                                			AND `warehouse_detail`.`type` = 1
                                			AND `warehouse_detail`.`actived` = 1
                                GROUP BY warehouse_detail.prod_id");
	GLOBAL $sum;
	$data = '';
	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr>';
		for ( $i = 0 ; $i < 2 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
		}
		$data .= '</tr>';
	}
	return $data;
}
function print5($letter_id){
	$rsql = mysql_query("SELECT             `wd`.`barcode`,
											`production`.`name`,
											IF(ISNULL((SELECT  DISTINCT warehouse_producing.packer_id FROM warehouse_producing  WHERE warehouse_producing.warehouse_detail_id = wd.id AND NOT ISNULL(warehouse_producing.packer_id)   LIMIT 1)) ,
											IF(`wd`.`status` = 0, '<img src=\"media/images/delete1.png\">', '<img src=\"media/images/apply.png\">'),
																		'<img style=\"width: 15px; height: 15px;\" src=\"media/images/pack.png\">'
																	)
								FROM		 `warehouse_detail` AS wd
								LEFT JOIN `warehouse` ON `warehouse`.`id` = `wd`.`warehouse_id`
								LEFT JOIN	`production` ON `production`.`id` = `wd`.`prod_id`
		WHERE wd.actived=1 AND warehouse.a_letter_id='$letter_id' OR warehouse.d_letter_id='$letter_id'		");
	GLOBAL $sum;
	$data = '';
	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr>';
		for ( $i = 0 ; $i < 3 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
		}
		$data .= '</tr>';
	}
	return $data;
}

function GetAletterInfo($letter_id){
	$res = mysql_fetch_assoc(mysql_query("SELECT	`a_letter`.`id` as `id`,
			`a_letter`.`start_date` as `date`,
			CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
			`a_letter`.`comment` as `coment`
			FROM			`a_letter`
			LEFT JOIN		`client_objects` ON `a_letter`.`client_object_id` = `client_objects`.`id`
			LEFT JOIN		`client` ON `client`.`id` = `client_objects`.`client_id`
			WHERE			`a_letter`.`id` = '$letter_id'
			UNION
			SELECT	`d_letter`.`id` as `id`,
			`d_letter`.`start_date` as `date`,
			CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
			`d_letter`.`comment` as `coment`
			FROM			`d_letter`
			LEFT JOIN		`client_objects` ON `d_letter`.`client_object_id` = `client_objects`.`id`
			LEFT JOIN		`client` ON `client`.`id` = `client_objects`.`client_id`
			WHERE			`d_letter`.`id` = '$letter_id'
			"));
	return $res;
}
function GetPage($res = '',$tab){
	if($tab==1){
		$data = '
		<fieldset id="fiel_bank">
	    	<legend>ბარათები</legend>
		    <div class="inner-table">
			    <div id="dt_example" class="ex_highlight_row">
			        <div id="container" class="overhead_container">
			        	<div id="button_area"></div>
			            <div id="dynamic">
								<table class="display" style="width: 900px" id="table-3">
					                    <thead>
					                        <tr id="datatable_header">
					                            <th>ID</th>
					                            <th class="min">ბარათის ნომერი</th>
					                            <th style="width: 150px">თარიღი </th>
					                            <th style="width: 150px">თანხა</th>
					                            <th style="width: 150px">ფილიალი</th>
					                            <th style="width: 150px">შენიშვნა</th>

					                        </tr>
					                    </thead>
					                    <thead>
					                        <tr class="search_header">
					                            <th class="colum_hidden">
					                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            	                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            	                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                        </tr>
					                    </thead>
										<tfoot>
					                        <tr>
					                            <th>&nbsp;</th>
					                            <th>&nbsp;</th>
					                            <th><p align="right">ჯამი:<br/>სულ ჯამი:</th>
					                            <th align="left">&nbsp;</th>
					                            <th>&nbsp;</th>
												<th>&nbsp;</th>
					                        </tr>
					                    </tfoot>
					                </table>



			            </div>
			        </div>
			    </div>
			</div>
		</fieldset>
<input type="hidden" id="inv_id" value="'.$_REQUEST['id'].'">
	    </div>
	<div class="inner-table" >


	</div>';
	} else{
	GLOBAL $sum;
	$later='b';

	$reQ = mysql_fetch_assoc(mysql_query("
			SELECT
					 CONCAT('ბ–',`a_letter`.`id`) AS id,
					a_letter.request_date as start_date,
					`a_letter`.`finish_date` as end_date,
					request_sources.`name` as source,
					CONCAT(`client`.`name`,'  (',`client_objects`.`name`, ')') AS `client`,
					`client_objects`.`id` as `obj_id`,
					`a_letter`.`b_letter_status` as `b_letter_status`,
					`a_letter`.`b_letter_overhead_id` as `overhead_id`,
					client_object_persons.`name` as client_p,
					persons.`name` as obj_p
			FROM			`a_letter`
			LEFT JOIN		`client_objects` ON `a_letter`.`client_object_id` = `client_objects`.`id`
			LEFT JOIN		`client` ON `client`.`id` = `client_objects`.`client_id`
			LEFT JOIN   	request_sources ON request_sources.id=a_letter.source
			LEFT JOIN   	persons ON a_letter.receiver=persons.id
			LEFT JOIN   	client_object_persons ON client_object_persons.id=a_letter.requester
			WHERE			`a_letter`.`id` = '$res[id]'
UNION
			SELECT CONCAT('ე–',`d_letter`.`id`) AS id,
						d_letter.request_date as start_date,
						`d_letter`.`finish_date` as end_date,
						request_sources.`name` as source,
						CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
						`client_objects`.`id` as `obj_id`,
						`d_letter`.`e_letter_status` as `e_letter_status`,
						`d_letter`.`e_letter_overhead_id` as `overhead_id`,
						client_object_persons.`name` as client_p,
						persons.`name` as obj_p
			FROM			`d_letter`
			LEFT JOIN		`client_objects` ON `d_letter`.`client_object_id` = `client_objects`.`id`
			LEFT JOIN		`client` ON `client`.`id` = `client_objects`.`client_id`
			LEFT JOIN   	request_sources ON request_sources.id=d_letter.source
			LEFT JOIN   	persons ON d_letter.receiver=persons.id
			LEFT JOIN   	client_object_persons ON client_object_persons.id=d_letter.requester
			WHERE			`d_letter`.`id` = '$res[id]'"));

	$m="
		</table>
		</fieldset>

			<fieldset style='margin-top: 4px;'>
			<legend></legend>
				<table width='90%'>
				<tr>
				<td>მიმწოდებელი: $reQ[client_p]</td>
				<td></td>
				<td>მიმღები: $reQ[obj_p]</td>
				<td></td>
				</tr>
				</table>
			</fieldset>	";
	$data = "
		<div id='dialog-form'>
				<fieldset>
					<legend>$reQ[client]</legend>
					<table width='100%'>
						<tr>
							<td>შეკვეთის N: $res[id]</td>
							<td></td>
							<td>შეკვეთის დრო: $reQ[start_date]</td>
							<td></td>
						</tr>
						<tr>
							<td>შეკვეთის ფომა: $reQ[source]</td>
							<td></td>
							<td>მიტანის დრო: $reQ[end_date]</td>
							<td></td>
						</tr>

</table>
				</fieldset>
				<div style='padding: 2px;'></div>
				<fieldset>
	";
	if (substr($reQ[id],0,3)=='ე') {
		if($_REQUEST['rw']=='wr' & $_REQUEST['tab']==0){
			$data.='<table class="display dataTable" style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">რაოდენობა</td>
		</tr>';
			$data .= print4($res['id']);
			$data .=$m;
		}elseif ($_REQUEST['rw']=='wr' & $_REQUEST['tab']==1){
			$data.='<table class="display dataTable" style="width: 550px !important; height:25px;  border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr  class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">სტატუსი</td>
		</tr>';
			$data .= print5($res['id']);
					$data .=$m;
		}
		else{
		$data.='<table class="display dataTable"  style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr style="background-color: black !important; border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>სერვისი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">შტრიხკოდი</td>
		<td style="width: 10% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">ფასი</td>
		</tr>';

		$data .= print2($res['id']);
		}
	}else{
		if($_REQUEST['rw']=='wr' & $_REQUEST['tab']==0){
			$data.='<table class="display dataTable" style="width: 550px" cellpadding="0" cellspacing="0">
		<thead class="ui-widget-header">
		<tr style="border:1px !important; height:25px; color: white !important;">
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">რაოდენობა</td>
		</tr>
		</thead>';
			$data .= print3($res['id']);
					$data .=$m;
		}elseif ($_REQUEST['rw']=='wr' & $_REQUEST['tab']==1){
			$data.='<table class="display dataTable" style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<thead class="ui-widget-header">
		<tr  class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">სტატუსი</td>
		</tr>
		</thead>'	;
			$data .= print5($res['id']);
					$data .=$m;
		}
		else{
	$data.='
					<table  style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
						<tr style="background-color: #D9D9D9;border:1px solid black !important;">
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
							<td colspan="9"  style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important; text-align: center;">ჩატარებული სამუშაოები</td>
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
	                        <td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>						
	                   </tr>
						<tr style="background-color: #D9D9D9;!important; border:1px solid black !important;">
							<td style="width: 170px;font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
							<td style="width: 110px;font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ტონერი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ბარაბანი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">მაგნიტ. ლილ.</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">რეზინის PCR</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">გამწ. რაკელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">დოზ. რაკელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ჩიპი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">კორპუსი</span></td>
	                        <td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">სერვ გარაშე</span></td>   
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">საგარანტიო</span></td>
							<td style="font-size: 100%  !important; width: 110px !important; vertical-align: middle !important; text-align: center;">&nbsp;ფასი&nbsp;</td>
						</tr>';


	$data .= print1($res['id']);
	$data .='</table>
					<table >
						<div style="text-align: right; font-size: 10pt; margin-top: 4px;">
							<p>თანხა სულ :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;">' . addNull($sum) . '&nbsp;&nbsp;ლარი</span></p>
						</div>
					</table>';
		}
	}
	$data .= '



	    </div>
	<div class="inner-table" >


	</div>';}

	return $data;
}

?>